<?php
    
    class ElementTopbarTable extends Element {
        public function Render( $newtable = false ) {
            global $server;
            global $db;
            global $table;

            $tables = array();
            if ( !isset( $server[ 'loginrequired' ] ) ) {
                $tables = $db->Tables();
            }

            ?><div class="item">
                <a href="" onclick=""><img src="images/table.png" alt="table" title="Table" /></a>
                <select name="table" id="tableselect" style="min-width: 100px;"><?php
                    foreach ( $tables as $t ) {
                        ?><option onclick="Table.Select( this.parentNode, '<?php
                        echo $server[ 'name' ];
                        ?>', '<?php
                        echo $db->Name();
                        ?>' )"<?php
                        if ( $t->Name == $table->Name && !$newtable ) {
                            ?> selected="selected"<?php
                        }
                        ?>><?php
                        echo $t->Name;
                        ?></option><?php
                    }
                    if ( !isset( $server[ 'loginrequired' ] ) ) {
                        ?><option onclick="Table.Select( this.parentNode, '<?php
                        echo $server[ 'name' ];
                        ?>', '<?php
                        echo $db->Name();
                        ?>' )" value="##new##" class="createopt"<?php
                        if ( $newtable ) {
                            ?> selected="selected"<?php
                        }
                        ?>>New table..</option><?php
                    }
                ?></select><?php
                Element( 'modal/table/create' );
            ?></div><?php
        }
    }

?>
